//
//  UpChildTwoView.m
//  FoodCorner
//
//  Created by lanou3g on 16/2/27.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "UpChildTwoView.h"
#import "CollectionTableViewController.h"
#define WSelf self.frame.size.width
#define HSelf self.frame.size.height

@implementation UpChildTwoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self andSubView];
    }
    return self;
}

- (void)andSubView{
   
    
    self.buttonOne = [[UIButton alloc]init];
    [self setButtonDecription:self.buttonOne title:@"收藏"];
    [self.buttonOne addTarget:self action:@selector(cllectionAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.buttonTwo = [[UIButton alloc]init];
    [self setButtonDecription:self.buttonTwo title:@"订单"];
     [self.buttonTwo addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.buttonThree = [[UIButton alloc]init];
    [self setButtonDecription:self.buttonThree title:@"优惠"];
     [self.buttonThree addTarget:self action:@selector(discountAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.buttonFour = [[UIButton alloc]init];
    [self setButtonDecription:self.buttonFour title:@"积分"];
     [self.buttonFour addTarget:self action:@selector(intergralAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:_buttonFour];
    [self addSubview:_buttonTwo];
    [self addSubview:_buttonThree];
    [self addSubview:_buttonOne];
}

//对button做了部分封装
- (void)setButtonDecription:(UIButton *)but  title:(NSString *)title
{
    
    [but setTitle:title forState:(UIControlStateNormal)];
    [but setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    but.titleLabel.font = [UIFont systemFontOfSize:13];
    
}

- (void)layoutSubviews{
   

    self.buttonOne.frame = CGRectMake(HSelf *0.2, HSelf *0.3, HSelf *0.5, HSelf *0.3);
    self.buttonTwo.frame = CGRectMake(CGRectGetMaxX(self.buttonOne.frame)+HSelf*0.3*2, HSelf *0.3, HSelf *0.5, HSelf *0.3);
    self.buttonThree.frame = CGRectMake(CGRectGetMaxX(self.buttonTwo.frame)+HSelf*0.3*2, HSelf *0.3, HSelf *0.5, HSelf *0.3);
    self.buttonFour.frame = CGRectMake(CGRectGetMaxX(self.buttonThree.frame)+HSelf*0.3*2, HSelf *0.3, HSelf *0.5, HSelf *0.3);

}

//收藏按钮事件
- (void)cllectionAction:(UIButton *)button{
    
    //给button添加通知 控制器的跳转
    [[NSNotificationCenter defaultCenter] postNotificationName:@"cllectionController" object:nil];
    
}

//收藏按钮事件
- (void)orderAction:(UIButton *)button{
    
    //给button添加通知 控制器的跳转
    [[NSNotificationCenter defaultCenter] postNotificationName:@"orderController" object:nil];
    
}
//收藏按钮事件
- (void)discountAction:(UIButton *)button{
    
    //给button添加通知 控制器的跳转
    [[NSNotificationCenter defaultCenter] postNotificationName:@"discountController" object:nil];
    
}
//收藏按钮事件
- (void)intergralAction:(UIButton *)button{
    
    //给button添加通知 控制器的跳转
    [[NSNotificationCenter defaultCenter] postNotificationName:@"intergralController" object:nil];
    
}




















@end
